package sk.tuke.persistance;

import java.io.Serializable;
import javax.persistence.*;

@Entity
@org.hibernate.annotations.Proxy(lazy = false)
@Table(name = "DOCTOR")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("DOCTOR")
public class DoctorPo extends UserPo implements Serializable {

	private static final long serialVersionUID = 1L;

	public DoctorPo() {
	}

	@ManyToOne(targetEntity = DepartmentPo.class, fetch = FetchType.LAZY)
	@org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.LOCK })
	@JoinColumns({ @JoinColumn(name = "department_id", referencedColumnName = "id") })
	@org.hibernate.annotations.LazyToOne(value = org.hibernate.annotations.LazyToOneOption.NO_PROXY)
	private DepartmentPo department;

	@ManyToMany(targetEntity = PatientPo.class, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinTable(name = "DOCTOR_PATIENT", joinColumns = { @JoinColumn(name = "doctor_id") }, inverseJoinColumns = { @JoinColumn(name = "patient_id") })
	private java.util.Set<PatientPo> patients = new java.util.HashSet<PatientPo>();

	public void setDepartment(DepartmentPo value) {
		this.department = value;
	}

	public DepartmentPo getDepartment() {
		return department;
	}

	public void setPatients(java.util.Set<PatientPo> value) {
		this.patients = value;
	}

	public java.util.Set<PatientPo> getPatients() {
		return patients;
	}

	public String toString() {
		return super.toString();
	}

	public boolean equals(Object aObj) {
		if (aObj == this)
			return true;
		if (!(aObj instanceof DoctorPo))
			return false;
		DoctorPo doctor = (DoctorPo) aObj;
		if (getId() != doctor.getId())
			return false;
		return true;
	}

	public int hashCode() {
		int hashcode = 0;
		hashcode = hashcode + (int) getId();
		return hashcode;
	}

}
